
<!DOCTYPE html>
<html lang="zh-CN" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>nginx + 子域名实现站点管理 - 初一蛙鸣</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="Fechin,"> 
    <meta name="description" content="初一蛙鸣-前端-小程序-vue-react,主要思路1、先利用统配域名把所有的解析都指向装有nginx的主机
2、主机上分别再不同的端口运行多个项目
3、nginx通过监听host，代理到不同的端口
安装nginx123451、rpm -Uv,"> 
    
    <link rel="alternative" href="atom.xml" title="初一蛙鸣" type="application/atom+xml"> 
    <link rel="icon" href="/img/favicon.png"> 
    
    
    
    <meta name="twitter:card" content="summary"/>
    <meta name="twitter:title" content="nginx + 子域名实现站点管理 - 初一蛙鸣"/>
    <meta name="twitter:description" content="初一蛙鸣-前端-小程序-vue-react,主要思路1、先利用统配域名把所有的解析都指向装有nginx的主机
2、主机上分别再不同的端口运行多个项目
3、nginx通过监听host，代理到不同的端口
安装nginx123451、rpm -Uv,"/>
    
    
    
    
    <meta property="og:site_name" content="初一蛙鸣"/>
    <meta property="og:type" content="object"/>
    <meta property="og:title" content="nginx + 子域名实现站点管理 - 初一蛙鸣"/>
    <meta property="og:description" content="初一蛙鸣-前端-小程序-vue-react,主要思路1、先利用统配域名把所有的解析都指向装有nginx的主机
2、主机上分别再不同的端口运行多个项目
3、nginx通过监听host，代理到不同的端口
安装nginx123451、rpm -Uv,"/>
    
<link rel="stylesheet" href="/css/diaspora.css">

    <script>window.searchDbPath = "/search.xml";</script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<meta name="generator" content="Hexo 4.2.1"></head>

<body class="loading">
    <span id="config-title" style="display:none">初一蛙鸣</span>
    <div id="loader"></div>
    <div id="single">
    <div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <a class="iconfont icon-home image-icon" href="javascript:;" data-url="https://lhl946.gitee.io"></a>
    <div title="播放/暂停" class="iconfont icon-play"></div>
    <h3 class="subtitle">nginx + 子域名实现站点管理</h3>
    <div class="social">
        <div>
            <div class="share">
                <a title="获取二维码" class="iconfont icon-scan" href="javascript:;"></a>
            </div>
            <div id="qr"></div>
        </div>
    </div>
    <div class="scrollbar"></div>
</div>

    <div class="section">
        <div class="article">
    <div class='main'>
        <h1 class="title">nginx + 子域名实现站点管理</h1>
        <div class="stuff">
            <span>十二月 05, 2020</span>
            
  <ul class="post-tags-list" itemprop="keywords"><li class="post-tags-list-item"><a class="post-tags-list-link" href="/tags/nginx/" rel="tag">nginx</a></li><li class="post-tags-list-item"><a class="post-tags-list-link" href="/tags/%E9%83%A8%E7%BD%B2/" rel="tag">部署</a></li></ul>


        </div>
        <div class="content markdown">
            <h2 id="主要思路"><a href="#主要思路" class="headerlink" title="主要思路"></a>主要思路</h2><p>1、先利用统配域名把所有的解析都指向装有nginx的主机</p>
<p>2、主机上分别再不同的端口运行多个项目</p>
<p>3、nginx通过监听host，代理到不同的端口</p>
<h2 id="安装nginx"><a href="#安装nginx" class="headerlink" title="安装nginx"></a>安装nginx</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1、rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm #如果没有源，先添加yum源</span><br><span class="line">2、yum install -y nginx #安装</span><br><span class="line">3、nginx -v #检查是否安装成功</span><br><span class="line">4、nginx -t #查看配置文件目录</span><br><span class="line">5、vim /etc/nginx/nginx.config #编辑配置文件</span><br></pre></td></tr></table></figure>

<h2 id="在服务器上运行程序"><a href="#在服务器上运行程序" class="headerlink" title="在服务器上运行程序"></a>在服务器上运行程序</h2><p>1、如果是静态项目，直接放在一个文件夹放着就行</p>
<p>2、vue项目的话，把build后的dist文件夹传上来</p>
<p>3、springboot项目可以用java -jar xxx.jar &amp;将打包后的jar包跑起来</p>
<p>4、也可以在docker中把项目跑起来，记下映射端口</p>
<h2 id="代理"><a href="#代理" class="headerlink" title="代理"></a>代理</h2><p>添加一个server</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 需要运行的项目</span></span><br><span class="line">server &#123;</span><br><span class="line">    listen       80; </span><br><span class="line">    server_name  mall.lhl94666.cn; #监听这个地址</span><br><span class="line">    location / &#123;</span><br><span class="line">    	proxy_pass http://localhost:28089; #就是你程序跑起来的那个端口</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 静态项目</span></span><br><span class="line">server &#123;</span><br><span class="line">    listen    80;</span><br><span class="line">    server_name portal.lhl94666.cn;</span><br><span class="line">    location / &#123;</span><br><span class="line">         root   /opt/demo/portal; #网站根目录</span><br><span class="line">         index  index.html; #入口文件</span><br><span class="line">         try_files $uri $uri/ /index.html;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="重启nginx"><a href="#重启nginx" class="headerlink" title="重启nginx"></a>重启nginx</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nginx -s reload #重启nginx</span><br></pre></td></tr></table></figure>

<p>浏览器输入你刚刚配置的mall.lhl94666.cn就能看到效果啦~</p>

            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls" data-autoplay="false">
                <source type="audio/mpeg" src="">
            </audio>
            
                <ul id="audio-list" style="display:none">
                    
                        
                            <li title="0" data-url="http://link.hhtjim.com/163/425570952.mp3"></li>
                        
                    
                        
                            <li title="1" data-url="http://link.hhtjim.com/163/425570952.mp3"></li>
                        
                    
                </ul>
            
        </div>
        
        
    <div id="gitalk-container" class="comment link"
		data-enable="false"
        data-ae="false"
        data-ci=""
        data-cs=""
        data-r=""
        data-o=""
        data-a=""
        data-d="false"
    >查看评论</div>


    </div>
    
</div>


    </div>
</div>
</body>


<script src="//lib.baomitu.com/jquery/1.8.3/jquery.min.js"></script>
<script src="/js/plugin.js"></script>
<script src="/js/typed.js"></script>
<script src="/js/diaspora.js"></script>


<link rel="stylesheet" href="/photoswipe/photoswipe.css">
<link rel="stylesheet" href="/photoswipe/default-skin/default-skin.css">


<script src="/photoswipe/photoswipe.min.js"></script>
<script src="/photoswipe/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>






</html>
